package com.project.controller;

import com.project.bean.UserBean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

@RestController
@RequestMapping("upload")
public class UploadController {

    @RequestMapping("add")
    public String add(UserBean user, @RequestParam("myFile")MultipartFile mf) throws Exception{
        String fileName = mf.getOriginalFilename();
        fileName = System.currentTimeMillis()+fileName+fileName.substring(fileName.lastIndexOf("."));

        mf.transferTo(new File("F:/java作业文件夹/webTest/webFliterUpload/src/main/resources/static/html/img/"+fileName));

        user.setPic(fileName);
        System.out.println(user);

        return "ok";
    }
}
